<script type="text/javascript">
    {literal}
    
    function sendAction(action){
        $("#action").val(action);
        $("#submitting").submit();    
    }    
        
    $(document).ready(function() {
        $("#from").datepicker({ 
            dateFormat: "dd/mm/yy",
            firstDay: 1      
        });
        $("#to").datepicker({ 
            dateFormat: "dd/mm/yy",
            firstDay: 1      
        });
    });
    {/literal}
</script>

<h2 class="pageTitle">Monthly timesheet reports</h2>

<div class="menu-list">
    <form action="{$data.root}?input=monthly_timesheet_reports" method="post" id="submitting">
        <input type="hidden" name="goods" value="0" /><input type="checkbox" name="goods" value="1" {if $smarty.request.goods==1}checked="checked"{elseif !isset($smarty.request.action)}checked="checked"{/if} />Dodaný tovar&nbsp;
        <input type="hidden" name="servis" value="0" /><input type="checkbox" name="servis" value="1" {if $smarty.request.servis==1}checked="checked"{elseif !isset($smarty.request.action)}checked="checked"{/if} />Pravidelný servis&nbsp;
        <input type="hidden" name="other" value="0" /><input type="checkbox" name="other" value="1" {if $smarty.request.other==1}checked="checked"{elseif !isset($smarty.request.action)}checked="checked"{/if} />Služby mimo zmluvný rozsah&nbsp;<br/>
        Client: &nbsp;
        <select size="1" name="selectedClient" onchange="taskListOfClient(this.value)">
            <option value="">Please select</option>
            {foreach from=$data.clients item="client"}
                <option {if $smarty.session.user.user_type_id!=$smarty.const.USER_TYPE_CLIENT && $client.bad_payer==1}class="badPayer"{/if} {if $data.prefill.client==$client.klient_id}selected="selected"{/if} value="{$client.klient_id}">{$client.name}</option>
            {/foreach}
        </select>&nbsp;
        Task: &nbsp;
        <select size="1" name="selectedTask" id="selectedTask">
            <option value="">Please select</option>
            {foreach from=$data.tasks item="task"}
                <option {if $data.prefill.task==$task.taskId}selected="selected"{/if} value="{$task.taskId}">{$task.title}</option>
            {/foreach}
        </select>&nbsp;
        <br/>
        Period:
        <select size="1" name="selectedPeriod">
            {foreach from=$data.periods item="period" key="i"}
                <option {if $period.period==$data.prefill.today}selected="selected"{/if} value="{$period.period}">{$period.period}{if $period.locked==1}*{/if}</option>
            {/foreach}
        </select>
        &nbsp;<b>or</b>&nbsp;from
        <input name="selectedFrom" value="{$data.prefill.from}" type="text"  id="from" />
        &nbsp;to&nbsp;
        <input name="selectedTo" value="{$data.prefill.to}" type="text"  id="to" /> (must be filled from and to)
        <input id="action" name="action" value="" type="hidden" />
        <input value="Show" type="button" onclick="sendAction('show')" />
        {if $smarty.session.user.profile.userlevel != $smarty.const.USER_TYPE_CLIENT} 
        <input value="Lock / Unlock" type="button" onclick="sendAction('lock')" /> * locked
        {/if}
    </form>
</div>

{include $data.pathToError}

{if  $data.output|@count == 0} 
    No records.
{else}
    <div style="margin: 1em;">
        {if isset($data.prefill.from) && isset($data.prefill.from)}
            <a target="_blank" href="{$data.root}print.php?input=monthly_timesheet_reports&amp;selectedFrom={$data.prefill.from}&amp;selectedTo={$data.prefill.to}&amp;action=show&amp;selectedClient={$data.prefill.client}&amp;selectedTask={$data.prefill.task}&amp;goods={$smarty.request.goods}&amp;servis={$smarty.request.servis}&amp;other={$smarty.request.other}" class="basicButton">Print this report</a>
        {else}
            <a target="_blank" href="{$data.root}print.php?input=monthly_timesheet_reports&amp;selectedPeriod={$data.prefill.today}&amp;action=show&amp;selectedClient={$data.prefill.client}&amp;selectedTask={$data.prefill.task}&amp;goods={$smarty.request.goods}&amp;servis={$smarty.request.servis}&amp;other={$smarty.request.other}" class="basicButton">Print this report</a>
        {/if}
    </div>
    {foreach from=$data.output key="client_id" item="client"}
        <div style="margin: 0; padding: 0; page-break-after: always">
            <table class="protocol-list" style="font-size: 10px;">
                <tr>
                    <td colspan="2" style="vertical-align: top">
                        <h1 style="font-size: 14px; margin: 0px 0 5px 0; padding: 0">Príloha k faktúre:</h1>
                        <span style="font-size: 12px; margin: 0px; padding: 0; font-weight: bold">
                            Sumárny zoznam dodaných služieb a tovaru <br/>za obdobie 
                            {if isset($data.prefill.from) && isset($data.prefill.from)}
                                od {$data.prefill.from} do {$data.prefill.to}
                            {else}
                                {$data.prefill.todayMonth} {$data.prefill.todayYear}
                            {/if}<br/>
                            pre {$client.client_info.fullName}, IČO: {$client.client_info.ICO}
                        </span>
                    </td>
                    <td colspan="3" style="vertical-align: top">
                        <h1 style="font-size: 14px; margin: 0px 0 5px 0; padding: 0">
                            Alfa Centauri spol. s r.o.
                        </h1>
                        <span style="font-size: 12px; margin: 0px; padding: 0">
                            Pri strelnici 3, 821 04 Bratislava<br/>
                            Web: Internet: www.alfac.sk <br/>
                            E-mail:  office@alfac.sk
                        </span>
                    </td>
                    <td colspan="2" style="vertical-align: top">
                        <h1 style="font-size: 14px; margin: 0px 0 5px 0; padding: 0">Kontaktná osoba:</h1>
                        <span style="font-size: 12px; margin: 0px; padding: 0">
                            {$client.contact_info.name} {$client.contact_info.surname}<br/>
                            Email: {$client.contact_info.email}
                        </span>
                    </td>
                    <td colspan="2" style="vertical-align: top">
                        <img src="{$data.root}images/alfac_no_text.png" width="120" />
                    </td>
                </tr>
                <tr>
                    <th colspan="9">
                        <br/>
                    </th>
                </tr>
                {foreach from=$client.types key="name" item="recs"}
                    <tr>
                        <td style="padding: 10px 0" colspan="9" class="left-align"><strong>{$name}:</strong></td>
                    </tr>
                    <tr>
                        <td class="left-align" style="color:#0F192A; width: 300px; border-bottom: 1px solid gainsboro">Popis</td>
                        <td class="left-align" style="color:#0F192A; border-bottom: 1px solid gainsboro">Dátum</td>
                        <td class="left-align" style="color:#0F192A; border-bottom: 1px solid gainsboro">Sadzba</td>
                        <td class="left-align" style="color:#0F192A; border-bottom: 1px solid gainsboro">Množstvo</td>
                        <td class="left-align" style="color:#0F192A; border-bottom: 1px solid gainsboro">Jednotka</td>
                        <td class="left-align" style="color:#0F192A; border-bottom: 1px solid gainsboro">Jednotková cena</td>
                        <td class="left-align" style="color:#0F192A; border-bottom: 1px solid gainsboro">Cena bez DPH</td>
                        <td class="left-align" style="color:#0F192A; border-bottom: 1px solid gainsboro">Cena s DPH</td>
                        <td class="left-align" style="color:#0F192A; border-bottom: 1px solid gainsboro">Odovzdal</td>
                    </tr>
                    {foreach from=$recs item="record" key="k"}
                        <tr>
                            <td class="left-align" style="width: 300px;">{$record.description}</td>
                            <td class="left-align">{$record.date_formated}</td>
                            <td class="left-align">{$record.tariff_info.title}</td>
                            <td class="left-align">{$record.amount}</td>
                            <td class="left-align">{$record.tariff_info.unit}</td>
                            <td class="left-align">{$record.unit_price|round:"2"} €</td>
                            <td class="left-align">{$record.withoutDph|round:"2"} €</td>
                            <td class="left-align">{$record.withDph|round:"2"} €</td>
                            <td class="left-align">{$record.user_info.name} {$record.user_info.surname}</td>
                        </tr>
                    {/foreach}
                    <tr>
                        <td colspan="3" class="left-align" style="border-top: 1px solid gray;color:#0F192A"><b>Suma - {$name}:</b></td>
                        <td class="left-align" style="border-top: 1px solid gray;color:#0F192A"><b>{$client.sums.$name.totalAmount}</b></td>
                        <td class="left-align" style="border-top: 1px solid gray;color:#0F192A"></td>
                        <td class="left-align" style="border-top: 1px solid gray;color:#0F192A"></td>
                        <td class="left-align" style="border-top: 1px solid gray;color:#0F192A"><b>{$client.sums.$name.withoutDph|round:"2"} €</b></td>
                        <td class="left-align" style="border-top: 1px solid gray;color:#0F192A"><b>{$client.sums.$name.withDph|round:"2"} €</b></td>
                        <td class="left-align" style="border-top: 1px solid gray;color:#0F192A"></td>
                    </tr>
                {/foreach}
                <tr>
                    <th colspan="9" class="left-align">
                        <br/>
                        <br/>
                    </th>
                </tr>
                <tr>
                    <td colspan="6" class="left-align" style="font-size: 12px; padding: 10px 0;"><b>Celková suma:</b></td>
                    <td class="left-align" style="font-size: 12px; padding: 10px 0; "><b>{$client.total.withoutDph|round:"2"} €</b></td>
                    <td class="left-align" style="font-size: 12px; padding: 10px 0; "><b>{$client.total.withDph|round:"2"}  €</b></td>
                    <td class="left-align" style="font-size: 12px; padding: 10px 0; "></td>
                </tr>
                <tr>
                    <th colspan="9" class="left-align">
                        <br/>
                        <br/>
                    </th>
                </tr>
            </table>
        </div>
    {/foreach}
{/if}